package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.player.UserMail;
import com.yanqu.road.pb.mail.MailProto;
import com.yanqu.road.utils.string.StringUtils;

import java.util.Collection;

public class MailPb {

	public static MailProto.MailTempMsg.Builder parseMailTempMsg(UserMail mail) {
		if(null == mail){
			return null;
		}
		MailProto.MailTempMsg.Builder mailMsg = MailProto.MailTempMsg.newBuilder();
		mailMsg.setMailUid(mail.getMailUid());
		mailMsg.setMailType(mail.getMailType());
		mailMsg.setTitle(mail.getTitle());
		mailMsg.setContent(mail.getContent());
		if(StringUtils.isNullOrEmpty(mail.getAnnexes())) {
			mailMsg.setAnnexes("");
		}else {
			mailMsg.setAnnexes(mail.getAnnexes());
		}
		mailMsg.setSendTime((int) (mail.getSendTime().getTime() / 1000));
		mailMsg.setSendUserId(mail.getSendUserId());
		mailMsg.setSendNickName(mail.getSendNickName());
		mailMsg.setReceiveUserId(mail.getReceiveUserId());
		mailMsg.setIsRead(mail.isRead());
		mailMsg.setReadTime((int) (mail.getReadTime().getTime() / 1000));
		mailMsg.setIsGetReward(mail.isGetReward());
		mailMsg.setQrCode(mail.getQrCode()==null?"":mail.getQrCode());
		return mailMsg;
	}

	public static MailProto.MailListMsg.Builder parseMailListMsg(Collection<UserMail> mails) {
		MailProto.MailListMsg.Builder listMsg = MailProto.MailListMsg.newBuilder();
		if (null != mails) {
			for (UserMail mail : mails) {
				MailProto.MailTempMsg.Builder mailMsg = parseMailTempMsg(mail);
				if(null != mailMsg) {
					listMsg.addMailList(mailMsg);
				}
			}
		}
		return listMsg;
	}
}
